package com.example.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class ExcelDataListener extends AnalysisEventListener {

    // 通过 AnalysisContext 对象还可以获取当前 sheet，当前行等数据
    @Override
    public void invoke(Object data, AnalysisContext analysisContext) {
        ReadRowHolder readRowHolder = analysisContext.readRowHolder();
        Integer rowIndex = readRowHolder.getRowIndex();
        if(rowIndex < 10){
            return;
        }
        System.out.println("读取到数据:" + ((JSONObject)JSONObject.toJSON(data)).toString(SerializerFeature.PrettyFormat));
    }

    // 所有的数据解析完了调用
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
